﻿using System;
//using System.Collections.Generic;
//using System.Linq;
using System.Text;
using Microsoft.International.Converters.PinYinConverter;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;

namespace MCSharpLib.MUtility
{
    static class PinyinConvert
    {
        /// <summary>
        /// 返回单个简体中文字的拼音列表
        /// </summary>
        /// <param name="inputChar">简体中文单字</param>      
        public static ReadOnlyCollection<string> GetPinYinWithTone(Char inputChar)
        {
            ChineseChar chineseChar = new ChineseChar(inputChar);
            return chineseChar.Pinyins;
        }

        /// <summary>
        /// 返回单个简体中文字的拼音个数
        /// </summary>
        /// <param name="inputChar">简体中文单字</param>      
        public static short GetPinYinCount(Char inputChar)
        {
            ChineseChar chineseChar = new ChineseChar(inputChar);
            return chineseChar.PinyinCount;
        }

        /// <summary>
        /// 返回单个简体中文字拼音列表中的第一个拼音
        /// </summary>
        /// <param name="inputChar">简体中文单字</param>      
        public static string GetFirstPinYinCount(Char inputChar)
        {
            if (inputChar >= 0 && inputChar <= 47 || inputChar >= 123 && inputChar <= 127 || inputChar >= 91 && inputChar <= 96 || inputChar >= 58 && inputChar <= 64)
                return "";
            if (inputChar >= 48 && inputChar <= 57 || inputChar >= 97 && inputChar <= 122 || inputChar >= 65 && inputChar <= 90)
                return inputChar.ToString();
            if(Regex.Replace(inputChar.ToString(), @"[^\u4e00-\u9fa5]*", "")=="")
                return "";
            //得到第一个拼音
            return GetPinYinWithTone(inputChar)[0];
        }

    }
}
